<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="layui/css/layui.css">
<script type="text/javascript" src="<%=basePath%>js/jquery-1.8.3.js"></script>
<script type="text/javascript">
		$(function(){
		 
			
			 //多项删除
			 $("#delbut").click(function(){
				 if($("input[name='id']:checked").length==0){
					 alert("您还没有选中项，请选择再删除.");
				 }else{
					 //获取选中项的值
					 var ids="";
					 $("input[name='id']").each(function(i,obj){
						 if(obj.checked)
						   ids=ids+obj.value+",";
						 
					 });
					 ids=ids.substring(0,ids.length-1);
					 var roleId=$("input[name='roleId']:checked").val();
					
					 //异步删除
					//$("input[name='ck']:checked").parent().parent().remove();
					 
					 //发送异步请求   
					 $.post("<%=basePath%>delMoreRolePermission.do",{"ids":ids,"roleId":roleId},function(data){
						 
						 if(data!=null){
								alert("操作成功")
								location.href="<%=basePath%>getPermissionsByRoleId.do?id="+roleId;
							}else{
								alert("操作失败");
							}
						 
						 
					 },"json");
				 }
				 
			 });
			
			 
			 //批量添加
			 $("#addbut").click(function(){
				 if($("input[name='id']:checked").length==0){
					 alert("您还没有选中项，请选择再删除.");
				 }else{
					 //获取选中项的值
					 var ids="";
					 $("input[name='id']").each(function(i,obj){
						 if(obj.checked)
						   ids=ids+obj.value+",";
						 
					 });
					 ids=ids.substring(0,ids.length-1);
					 var roleId=$("input[name='roleId']:checked").val();
					 
					// alert(roleId);
					 //异步删除
					//$("input[name='ck']:checked").parent().parent().remove();
					 
					 //发送异步请求   
								 
					 $.post("<%=basePath%>insertMoreRolePermission.do",{"ids":ids,"roleId":roleId},function(data){
						 
						if(data!=null){
							alert("授权成功")
							location.href="<%=basePath%>getPermissionsByRoleId.do?id="+roleId;
						}else{
							alert("授权失败");
						}
						   
					 },"json"); 
				 }
				 
			 });
			 
			
			 
			 
			
		});

</script>
<title>Insert title here</title>
</head>
<body class="layui-layout-body">

<center>
权限管理>>>
<hr>
角色列表<br>
	&lt;&lt;&lt;<a href="<%=basePath%>getPermissionsByRoleId.do?id=1"><input type="radio" class="ss" name="roleId" value="1"> 系统管理员</a>>>>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	&lt;&lt;&lt;<a href="<%=basePath%>getPermissionsByRoleId.do?id=2"><input type="radio" class="ss" name="roleId" value="2">会员</a>>>>
<hr>	
	
	<table border="1px" style="width: 800px; ">
			<tr>
			<th>已经拥有的权限 	<input type="button" id="delbut" value="撤销权限">	</th>
			<th>未拥有的权限   <input type="button" id="addbut" value="授权">	</th>
			</tr>
	
	<tr>
			<!-- 已经拥有的权限 -->
		<td>
		<c:forEach items="${permissionsList }" var="p" varStatus="status">
				<input type="checkbox" value="${p.id }" name="id"> ${p.name }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<c:if test="${status.index%2==0 }">
					<br>
				</c:if>
		</c:forEach>
		</td>
		
		
		
			<!-- 未拥有的权限  -->
		<td>
			<c:forEach items="${unpermissionsList }" var="p" varStatus="status">
				<input type="checkbox" value="${p.id }" name="id"> ${p.name }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<c:if test="${status.index%2==0 }">
					<br>
				</c:if>
		</c:forEach>
		</td>
	</tr>
	</table>
</center>
	

	
		
		
</body>
</html>